<template>
    <div id="printMe" class="jurisdiction">
        <el-row style="text-align: right;margin: 10px 0px;">
            <el-col>
                <el-button type="success" @click="add">新疆权限</el-button>
                <el-button type="success" @click="export2Excel">导出excel</el-button>
                <el-button type="default" @click="$router.push('/geolocation')">定位页面</el-button>
                <el-button type="default" @click="$router.push('/editor')">富文本编辑器</el-button>
                <el-button type="default" @click="box">点击弹出消息对话框</el-button>
                <el-button v-print="'#printMe'" type="default">打印</el-button>
            </el-col>
        </el-row>
        <el-row>
            <el-table  :data="roleData" style="width: 100%" border>
                <el-table-column type="index" label="序号" width="200" align="center" :index="indexSort">
                </el-table-column>
                <el-table-column prop="permissionName" label="权限名" align="center">
                </el-table-column>
                <el-table-column prop="url" label="VUE地址" align="center">
                </el-table-column>
                <el-table-column prop="updateDate" label="更新时间" align="center">
                </el-table-column>
                <el-table-column label="操作" align="center">
                    <template slot-scope="scope">
                        <span class="el-tag el-tag--warning el-tag--small" style="cursor: pointer;" @click="updateRow(scope.$index,scope.row, houseCats)" size="mini">
                        修改
                        </span>
                        <span class="el-tag el-tag--danger el-tag--small" style="cursor: pointer;" @click="deleteRow(scope.$index ,scope.row.shTypeId, houseCats)" type="danger" size="mini">
                        删除
                        </span>
                    </template>
                </el-table-column>
            </el-table>
        </el-row>
        <el-row style="text-align: right;">
            <el-pagination
                @size-change="handleSizeChange"
                @current-change="handleCurrentChange"
                :current-page="currentPage"
                :page-sizes="[15, 50, 100, 200]"
                :page-size="pageSize"
                layout="->, sizes, prev, pager, next, jumper, total"
                :total="totalElements"
            ></el-pagination>
        </el-row>
        <add :off.sync="addPermissionDialog"></add>
    </div>    
</template>

<script>
    import { getPerssionList, addPerssion } from "@/api/jurisdiction.js"
    import { excel } from "@/util/excel.js"
    import * as util from "@/util/util.js"
    export default {
        name: "jurisdiction",
        components: {
           "add": () => import("./add.vue")
        },
        data(){
            return {
                addPermissionDialog: false,
                pageSize: 15,
                currentPage: 1,
                totalElements: 0,
                totalPages: 1,
                roleData:[
                ]
            }
        },
        mounted(){
            // 创建构造器
            // var Profile = Vue.extend({
            //     template: '<p>{{firstName}} {{lastName}} aka {{alias}}</p>',
            //     data: function () {
            //         return {
            //             firstName: 'Walter',
            //             lastName: 'White',
            //             alias: 'Heisenberg'
            //         }
            //     }
            // })
            // // 创建 Profile 实例，并挂载到一个元素上。
            // let instance = new Profile().$mount();
            // document.getElementById("test").appendChild(instance.$el);
        },
        created(){
            this.getList();
            // this.$jurisdiction.get().then(
            //     res => {
            //         console.log("res创建实例发送请求");
            //     },
            //     err => {}
            // );
            // this.$axios.get("/Get/list1").then(
            //     res => {
            //         console.log("res模拟接口", res);
            //     },
            //     err => {}
            // );
           
            // for(var i = 0; i < 100; i++){
            //     this.roleData.push({
            //         roleName: "仓库管理员" + i
            //     });
            // }
            // this.totalElements = this.totalElements;
        },
        methods: {
            add(){
                this.addPermissionDialog = true;
            },
            getList(){
                getPerssionList({
                    currentPage: this.currentPage,
                    pageSize: this.pageSize,
                    total: 10
                }).then(
                    res => {
                        console.log("res权限接口", res);
                        this.roleData = res.data.list;
                        this.roleData.forEach((e) => {
                            e.updateDate = util.timestampToTime(e.updateDate);
                        });
                        this.totalElements = res.data.total;
                    },
                    err => {}
                );
            },
            deleteRow(){

            },
            box(){
                this.$toast("自定义toast", 3000);
            },
            export2Excel() {
                /* 第一个参数是导出的数组对象，第二个参数是表头title，第三个参数是文件名*/
                const data = [ 
                    {A:"1111",B:"2222"},

                    {A: "1111",B:"2222"},

                    {A: "1111",B: "2222"}

                ];

                const header = {header: ["id", "jurisdiction"] }
                this.$outputXlsxFile(this.roleData, header, "jurisdiction");
    // 　　　　　　require.ensure([], () => {
    // 　　　　　　　　const { export_json_to_excel } =   
    //                         require('@/src/vendor/Export2Excel');
    // 　　　　　　　　const tHeader = ['序号', '权限名称'];
    // 　　　　　　　　const filterVal = ['id', "jurisdiction"];
    // 　　　　　　　　const list = this.roleData;
    // 　　　　　　　　const data = this.formatJson(filterVal, list);
    // 　　　　　　　　export_json_to_excel(tHeader, data, '列表excel');
    // 　　　　　　})
    　　　　},
    　　　　formatJson(filterVal, jsonData) {
    　　　　　　return jsonData.map(v => filterVal.map(j => v[j]))
    　　　　},
            updateRow(){

            },
            //序号
            indexSort(index) {
                if (this.currentPage > 1) {
                    index = (this.currentPage - 1) * this.pageSize + index + 1;
                } else {
                    index = index + 1;
                }
                return index;
            },
            handleSizeChange(val) {
                this.pageSize = val;
                this.getList();
                console.log(`每页 ${val} 条`);
            },
            handleCurrentChange(val) {
                this.currentPage = val;
                this.getList();
                console.log(`当前页: ${val}`);
            }
        }
    }
</script>

<style lang="less">
.jurisdiction{
    
}
</style>